﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using NetSysData;

namespace BladeTecWebApplication.Admin
{
	public partial class Default : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{

			if (!Page.IsPostBack)
			{
				NetSysData.NetSysData data = new NetSysData.NetSysData();
				APPLICANT[] upcomingApplicants = data.GetUpcomingInterviews();
				GetRecentAttempts_Result[] recentAttempts = data.GetRecentAttempts();

				if (upcomingApplicants.Count() > 0)
				{
					string tableHtml = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
					foreach (APPLICANT a in upcomingApplicants)
					{
						tableHtml += "<tr>";
						tableHtml += "<td><span class=\"ui-icon ui-icon-person\"></span></td>";
						tableHtml += "<td><a class=\"dashboardLink\" href=\"EditApplicant.aspx?applicant_id="+a.APPLICANT_ID+"\">" + a.FIRST_NAME + " " + a.LAST_NAME + "</a></td>";
						tableHtml += "<td style=\"width:20px\">&nbsp;</td>";
						tableHtml += "<td>" + DateTime.Parse(a.INTERVIEW_DATE.ToString()).ToString("d") + "</td>";
						tableHtml += "</tr>";
					}
					tableHtml += "</table>";

					pnlUpcomingInterviews.Controls.Add(new LiteralControl(tableHtml));
				}
				else
				{
					pnlUpcomingInterviews.Controls.Add(new LiteralControl("There are interviews within the next 30 days."));
				}

				if (recentAttempts.Count() > 0)
				{
					string tableHtml = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";

					foreach (GetRecentAttempts_Result result in recentAttempts)
					{
						tableHtml += "<tr>";
						tableHtml += "<td><span class=\"ui-icon ui-icon-person\"></span></td>";
						tableHtml += "<td><a class=\"dashboardLink\" href=\"EditAttempt.aspx?attempt_id=" + result.ATTEMPT_ID + "\">" + result.FULL_NAME + "</a></td>";
						tableHtml += "<td style=\"width:20px\">&nbsp;</td>";
						tableHtml += "<td>" + DateTime.Parse(result.ATTEMPT_DATE.ToString()).ToString("d") + "</td>";
						tableHtml += "</tr>";
					}

					tableHtml += "</table>";
					pnlRecentQuizzes.Controls.Add(new LiteralControl(tableHtml));
				}
				else
				{
					pnlRecentQuizzes.Controls.Add(new LiteralControl("There are no quiz attempts within the last 30 days."));
				}

			}

		}
	}
}